import {createRouter, createWebHistory} from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
    {
        path: '/',
        name: 'home',
        component: HomeView,
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/login',
        name: 'login',
        component: () => import(/* webpackChunkName: "about" */ '@/views/LoginView.vue'),
        meta: {
            title: "后台管理系统-登录"
        }
    },
    {
        path: '/city/index',
        name: 'city',
        component: () => import(/* webpackChunkName: "about" */ '@/views/city/CityIndexView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/menu/index',
        name: 'menu',
        component: () => import(/* webpackChunkName: "about" */ '@/views/menu/MenuIndexView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/menu/add',
        name: 'menu_add',
        component: () => import(/* webpackChunkName: "about" */ '@/views/menu/MenuEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/menu/edit/:id',
        name: 'menu_edit',
        component: () => import(/* webpackChunkName: "about" */ '@/views/menu/MenuEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/website/index',
        name: 'website',
        component: () => import(/* webpackChunkName: "about" */ '@/views/website/WebsiteIndexView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/friendLink/index',
        name: 'friend_link',
        component: () => import(/* webpackChunkName: "about" */ '@/views/friendLink/FriendLinkIndexView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/friendLink/add',
        name: 'friend_link_add',
        component: () => import(/* webpackChunkName: "about" */ '@/views/friendLink/FriendLinkEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/friendLink/edit/:id',
        name: 'friend_link_edit',
        component: () => import(/* webpackChunkName: "about" */ '@/views/friendLink/FriendLinkEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/notice/index',
        name: 'notice',
        component: () => import(/* webpackChunkName: "about" */ '@/views/notice/NoticeIndexView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/notice/add',
        name: 'notice_add',
        component: () => import(/* webpackChunkName: "about" */ '@/views/notice/NoticeEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    },
    {
        path: '/notice/edit/:id',
        name: 'notice_edit',
        component: () => import(/* webpackChunkName: "about" */ '@/views/notice/NoticeEditView.vue'),
        meta: {
            title: "后台管理系统"
        }
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title || "后台管理系统";
    const cacheMenu = window.sessionStorage.getItem(`${to.name}_option_button`)
    if (to.name !== from.name && cacheMenu) {
        //删除操作菜单缓存
        window.sessionStorage.removeItem(`${to.name}_option_button`)
    }
    next();
})

export default router
